<% content_for :content do %>

  <!-- widget grid -->
  <section id="widget-grid" class="">
  

    <div class="row">
      <div class="col-sm-12">
        <div class="well">
          <%= simple_form_for :account, url: admin_accounts_path, :defaults => { :input_html => { :class => "form-control" } }, method: 'get', html: { class: "form-inline" } do |f| %>
            <%= f.hidden_field :account_group, value: params[:account][:account_group] %>
            <div class="form-group string">
              <%= f.text_field :mobile_number, class: "form-control", value: params[:account][:mobile_number], placeholder: "手机号" %>
            </div>
            <label>注册时间</label>
            <div class="form-group string">
              <%= f.text_field :start_date, class: "form-control datepicker", "data-dateformat" => "yy-mm-dd", value: params[:account][:start_date], placeholder: "From" %>
            </div>
            <div class="form-group string">
              <%= f.text_field :end_date, class: 'form-control datepicker', "data-dateformat" => "yy-mm-dd", value: params[:account][:end_date], placeholder: "To" %>
            </div>
            <%= f.submit "搜 索", :class => "btn btn-default"%>
          <% end %>
        </div> <!-- end well div -->
        <% if current_admin.can?(controller: "admin/accounts", action: "new") %>
        <% if @account_group %>
        <div class="well">
          <%= form_tag import_admin_accounts_path(:account_group_id => @account_group.id), :multipart => true , class: "form-inline", role: "search" do %>
          <div class="form-group">
            <div>
              <%= file_field_tag "file", class: "btn btn-default btn-sm form-control" %>
            </div>
          </div>
          <%= hidden_field_tag :terminal_group_id,@account_group.id%>
          <%= submit_tag "账号导入", class: "btn btn-default" %>
          <%= link_to "添加用户", new_admin_account_path(account_group_id: @account_group.id), :class => 'btn btn-default', :remote => true %>
          <% end %>
        </div> <!-- end well div -->
        <% end %>
        <% end %>

      </div>
    </div>

    <!-- row -->
    <div class="row">
  
      <!-- NEW WIDGET START -->
      <article class="col-xs-12 col-sm-12 col-md-12 col-lg-12">

        <% if flash[:success].present? %>
          <div class="alert alert-success fade in">
            <button class="close" data-dismiss="alert">
              ×
            </button>
            <i class="fa-fw fa fa-check"></i>
            <strong>成功</strong> <%= flash[:success] %>
          </div>
        <% elsif flash[:error].present? %>
          <div class="alert alert-danger fade in">
            <button class="close" data-dismiss="alert">
              ×
            </button>
            <i class="fa-fw fa fa-times"></i>
            <strong>错误!</strong> <%= flash[:error] %>
          </div>
        <% end %>
  
        <!-- Widget ID (each widget will need unique ID)-->
        <div class="jarviswidget jarviswidget-color-darken" id="wid-id-1" data-widget-editbutton="false" data-widget-colorbutton="false" data-widget-deletebutton="false">
          <!-- widget options:
          usage: <div class="jarviswidget" id="wid-id-0" data-widget-editbutton="false">

          data-widget-colorbutton="false"
          data-widget-editbutton="false"
          data-widget-togglebutton="false"
          data-widget-deletebutton="false"
          data-widget-fullscreenbutton="false"
          data-widget-custombutton="false"
          data-widget-collapsed="true"
          data-widget-sortable="false"

          -->
          <header>
            <span class="widget-icon"> <i class="fa fa-table"></i> </span>
            <h2>帐号列表</h2>
          </header>

          <!-- widget div-->
          <div>

            <!-- widget edit box -->
            <div class="jarviswidget-editbox">
              <!-- This area used as dropdown edit box -->
            </div>
            <!-- end widget edit box -->

            <!-- widget content -->
            <div class="widget-body no-padding">

              <p class="alert alert-info no-margin">
                <i class="fa-fw fa fa-info"></i>共有<%= @accounts.total_count %>条记录
              </p>

              <table class="table table-bordered table-striped">
                <thead>
                  <tr>
                    <th>所属分组</th>
                    <th>级别</th>
                    <th>手机号</th>
                    <th>姓名</th>
                    <th>归属地</th>
                    <%= sortable "account_signin_counter","签到" %>
                    <%= sortable "imported","帐号类型" %>
                    <%= sortable "created_at","注册时间" %>
                    <th>注册终端</th>
                    <%= sortable "last_seen","最近签到" %>
                    <th>操作</th>
                  </tr>
                </thead>
                <tbody>
                <% @accounts.each do |item| %>
                  <tr id='item-<%= item.id %>'>
                    <td><%= item.account_group.try(:group_name) %></td>
                    <td><%= item.level %></td>
                    <td>
                      <%= item.mobile_number %>
                    </td>
                    <td><%= item.name %></td>
                    <td><%= item.phone_detail_info %></td>
                    <td>
                      <%= item.account_signin_counter %>
                    </td>
                    <td><%= item.display_imported %></td>
                    <td>
                      <%= item.created_at.stamp("2013-03-12") %>
                    </td>
                    <td><%= item.register_terminal.try(:mac) %></td>
                    <td>
                      <%= item.last_seen.stamp("2013-03-12") if item.last_seen %>
                    </td>
                    <td>
                      <%= link_to '编辑', edit_admin_account_path(item), remote: true if current_admin.can?(controller: "admin/accounts", action: "edit") %> 
                      <%= link_to '删除', admin_account_path(item), method: :delete, remote: true, confirm: '是否确定删除?' if current_admin.can?(controller: "admin/accounts",action: "destroy") %>
                    </td>
                  </tr>
                <% end %>
                </tbody>
              </table>
              <div class="dt-row dt-bottom-row"><div class="row"><div class="col-sm-6"><div class="dataTables_info" id="datatable_fixed_column_info"></div></div><div class="col-sm-6 text-right"><%= paginate @accounts %></div></div></div>
            </div>
            <!-- end widget content -->

          </div>
          <!-- end widget div -->

        </div>
        <!-- end widget -->
  
      </article>
      <!-- WIDGET END -->

    </div>
  
    <!-- end row -->

    <ul>
      <% %w{day week month year}.each do |date_part| %>
        <li><%= link_to "注册用户数图(#{date_parts[date_part]})",admin_accounts_path((params[:account][:date_part] = date_part;params[:chart]=true;params)) ,:remote => true %></li>
      <% end %>
    </ul>

  </section>
  <!-- end widget grid -->
<% end %>
